package servlet;

import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import bean.Alarm;
import bean.Detection;
import bean.Online;
import dao.baojingdeo;
import dao.chartdeo;
import dao.jiancedeo;
import dao.onlinedeo;


public class ChartServlet extends HttpServlet{
	public void doGet(HttpServletRequest request, HttpServletResponse response)  
            throws ServletException, IOException {  
        this.doPost(request, response);  
    }  
    public void doPost(HttpServletRequest request, HttpServletResponse response)  
            throws ServletException, IOException {
    	request.setCharacterEncoding("utf-8");  
    	response.setContentType("text/html;charset=utf-8");   
    	
        String area =request.getParameter("Sel_Area");  
        int company_id=Integer.parseInt(request.getParameter("SeltPolluteSource"));
        String outlet_id = request.getParameter("SeltDischargePort");  
        String divio =request.getParameter("diviosr");  
        String date=request.getParameter("TxtSearchDataTime");
    	
        chartdeo db = new chartdeo();
       
        String sql=" ";
  
     	switch(divio)
       	{
       		case "油烟浓度":
       			 sql = " select b.oil_con from outlet a inner join monitorData b on a.outlet_id=b.outlet_id inner join company c on a.company_id=c.company_id where  c.area='"+area+"' and c.company_id='"+company_id+"' and a.outlet_id='"+outlet_id+"'";
       	 	 break;
       		case "联动比":
       			 sql = " select b.unite from outlet a inner join monitorData b on a.outlet_id=b.outlet_id inner join company c on a.company_id=c.company_id where  c.area='"+area+"' and c.company_id='"+company_id+"' and a.outlet_id='"+outlet_id+"'";
       	  	break;
       		case "温度":
      			 sql = " select b.temperature from outlet a inner join monitorData b on a.outlet_id=b.outlet_id inner join company c on a.company_id=c.company_id where  c.area='"+area+"' and c.company_id='"+company_id+"' and a.outlet_id='"+outlet_id+"'";
      	  	break;
       		case "湿度":
      			 sql = " select b. humidity outlet a inner join monitorData b on a.outlet_id=b.outlet_id inner join company c on a.company_id=c.company_id where  c.area='"+area+"' and c.company_id='"+company_id+"' and a.outlet_id='"+outlet_id+"'";
      	  	break;
       		case "压力":
      			 sql = " select b.pressure from outlet a inner join monitorData b on a.outlet_id=b.outlet_id inner join company c on a.company_id=c.company_id where  c.area='"+area+"' and c.company_id='"+company_id+"' and a.outlet_id='"+outlet_id+"'";
      	  	break;
       			default:
       	}
        
        ArrayList<Detection> list = null;
		try {
			list =db.getChartList(sql,divio,date);
		} catch (SQLException e) {
			e.printStackTrace();
		}
        request.setAttribute("list", list);  
        request.getRequestDispatcher("/data query/DataChart.jsp").forward(request, response);  
    }
}
